package com.example.teamtribe.main.club.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.example.teamtribe.R;
import com.example.teamtribe.base.BaseActivity;
import com.example.teamtribe.database.Posting;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

public class ActivityActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity);
        TextView tvTitle = findViewById(R.id.tv_title);
        int teamId = getIntent().getIntExtra("teamId", 0);
        List<Posting> activities = new ArrayList<>();
        if (teamId == 0) {
            tvTitle.setText("我的社团活动");
            List<Posting> a = DataSupport.findAll(Posting.class);
            if (a != null && !a.isEmpty())
                activities.addAll(a);
        } else {
            tvTitle.setText("社团活动");
            List<Posting> a = DataSupport.where("teamId = ?", teamId + "").find(Posting.class);
            if (a != null && !a.isEmpty())
                activities.addAll(a);
        }

        ActivityAdapter adapter = new ActivityAdapter(activities);
        RecyclerView recyclerView = findViewById(R.id.rv_activity);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

}
